<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="门店编码">
              <a-input placeholder="请输入门店编码" v-model="queryParam.code"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="门店名称">
              <a-input placeholder="请输入门店名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="客户编码">
                <a-input placeholder="请输入客户编码" v-model="queryParam.custCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="客户名称">
                <a-input placeholder="请输入客户名称" v-model="queryParam.custName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="大区">
                <a-input placeholder="请输入大区" v-model="queryParam.dqOrgName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="省区">
                <a-input placeholder="请输入省区" v-model="queryParam.provinceOrgName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="城市">
                <a-input placeholder="请输入城市" v-model="queryParam.cityOrgName"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
               <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleActModal" type="primary" icon="plus">添加门店</a-button>
      <a-button type="primary" icon="download" @click="downExportXls('actterm_report')">导出</a-button>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
          </a-popconfirm>
          <a-divider type="vertical" />
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->
    <!-- 表单区域 -->
    <act-term-modal  modal-width="90%"
                     ref="ActTermModal"
                     @ok="handelSaveWhite" />
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import TpmActSpecialDetailModal from './modules/TpmActSpecialDetailModal'
import { PageListMixin } from '@/mixins/PageListMixin'
import ActTermModal from '@views/tpm/act/modules/ActTermModal'
import { postAction } from '@api/manage'

export default {
  name: 'TpmActSpecialDetailList',
  mixins: [PageListMixin],
  props:["tempUuid"],
  components: {
    ActTermModal,TpmActSpecialDetailModal
  },
  data() {
    return {
      description: '专项活动明细管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        }
        ,
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        },
        {
          title: '门店编码',
          align: 'center',
          dataIndex: 'code'
        },
        {
          title: '门店名称',
          align: 'center',
          dataIndex: 'name'
        },
        {
          title: '上级客户编码',
          align: 'center',
          dataIndex: 'custCode'
        },
        {
          title: '上级客户名称',
          align: 'center',
          dataIndex: 'custName'
        },
        {
          title: '城市',
          align: 'center',
          dataIndex: 'cityOrgName'
        },
        {
          title: '省区',
          align: 'center',
          dataIndex: 'provinceOrgName'
        },
        {
          title: '大区',
          align: 'center',
          dataIndex: 'dqOrgName'
        }
      ],
      url: {
        list:  window._CONFIG['domianTpmURL']+'/act/tpmActSpecialDetail/findPageList',
        delete:  window._CONFIG['domianTpmURL']+'/act/tpmActSpecialDetail/delete',
        deleteBatch: window._CONFIG['domianTpmURL']+'/act/tpmActSpecialDetail/deleteBatch',
      }
    }
  },
  created() {
    this.queryParam.tempUuid = this.tempUuid
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    handelSaveWhite(terms) {

      const record = { tempUuid: this.tempUuid }
      record.details = terms
      var that = this
      postAction(window._CONFIG['domianTpmURL'] + '/act/tpmActSpecialDetail/saveOrUpdate', record).then(async (res) => {
        if (res.success) {
          that.$message.success(res.message)
          await this.loadData()
          this.$refs.ActTermModal.close()
        } else {
          this.$message.warning(res.message)
        }
      }).finally(() => {
        this.$refs.ActTermModal.confirmLoading = false
      })
    },
    async handleActModal(record) {
      this.$refs.ActTermModal.showModal(this.tempUuid)
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>